
#include "arm_math.h"
#include "arm_const_structs.h"
#include <stdio.h>

#define TEST_LENGTH_SAMPLES 2048

extern float32_t testInput_f32_10khz[TEST_LENGTH_SAMPLES];
static float32_t testOutput[TEST_LENGTH_SAMPLES/2];


static uint32_t fftSize = 1024;
static uint32_t ifftFlag = 0;
static uint32_t doBitReverse = 1;
static arm_cfft_instance_f32 varInstCfftF32;

static int testIndex = 0;

static float testtmp_f32_10khz[2048];
static int32_t adcbuffer[2048];

int32_t fft_main(void)
{

  arm_status status;
  float32_t maxValue;

  status = ARM_MATH_SUCCESS;

  status=arm_cfft_init_f32(&varInstCfftF32,fftSize);

  //memcpy(testtmp_f32_10khz,testInput_f32_10khz,sizeof(testInput_f32_10khz));
  adc_samp(adcbuffer,2048);
  for(int i=0; i<2048;i ++)
  {
	  testtmp_f32_10khz[i] = (float)adcbuffer[i];
  }
  arm_cfft_f32(&varInstCfftF32, testtmp_f32_10khz, ifftFlag, doBitReverse);

  arm_cmplx_mag_f32(testtmp_f32_10khz, testOutput, fftSize);

  /* Calculates maxValue and returns corresponding BIN value */
  arm_max_f32(testOutput, fftSize, &maxValue, &testIndex);

  int32_t out = 0;

  for(int i=0; i<TEST_LENGTH_SAMPLES; i++)
  {
	  if(i>TEST_LENGTH_SAMPLES/2)
	  {
		  out = testOutput[i-TEST_LENGTH_SAMPLES/2]/1024;
	  }
	  else
	  {
		  out = testOutput[i]/1024;
	  }
      printf("/*%ld,%ld*/\r\n", adcbuffer[i],out);
  }

}

 /** \endlink */
